package com.own.testapp.base;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.okgo.OkGo;
import com.okgo.model.HttpParams;
import com.okgo.model.Response;
import com.own.testapp.callback.ResultListener;
import com.own.testapp.callback.StringDialogCallback;
import com.own.testapp.utils.LoggerUtils;

import okhttp3.Call;

import static com.own.testapp.Constants.URL_JSONOBJECT;

/**
 * com.own.testapp
 *
 * @author ly-zhuqg
 * @date create at 2017/9/22
 * @修订 1.修改内容   by 修改人  at 修改日期
 */
public class BaseNetActivity extends BaseActivity implements ResultListener
{
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
    }

    public void getDataFromNet(HttpParams params, final ResultListener resultListener, final int type ){
        OkGo.<String>post(URL_JSONOBJECT)
                .tag(this)
                .params(params)
                .execute(new StringDialogCallback(mActivity) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        resultListener.handleSuccess(response.body(),response.getRawCall(),response.getRawResponse(),type);
                    }

                    @Override
                    public void onError(Response<String> response) {
                        resultListener.handleError(response.getRawCall(),response.getRawResponse(),type);
                    }
                });
    }

    @Override
    public void handleSuccess(String data, Call call, okhttp3.Response response, int type)
    {
        //这里统一处理某些事情
        LoggerUtils.e("data", "请求数据返回：" + data);

    }

    @Override
    public void handleError(Call call, okhttp3.Response response, int type)
    {
    }
}
